Example: Send external events to other portlets

Example: Send external events to other portlets

This example shows how to develop a plugin for the interview portlet that sends an event to another portlet. The example consists of:

Event sender

The source code for this plugin can be found in the examples\interview-portlet\event-sending directory of the Java runtime zip.

The plugin consists of one Java class PortletEventSender which implements the OnAfterProcessActionEventHandler interface. The handleEvent method accesses the SessionContext object in the OnAfterProcessActionEvent to determine whether a goal is known. If so, it raises an external event to other portlets using the following code:

QName qname = new QName("http://oracle.com/opa/interview/portlet/10.0" , "GoalKnown");
event.getActionResponse().setEvent(qname, goal.getId());

 

Additionally, the Oracle Policy Automation Interview Portlet is declared as a publisher of the GoalKnown event by way of the following entries in portlet.xml for the Oracle Policy Automation Interview Portlet:

 

In the portlet element:

<supported-publishing-event>
      <qname xmlns:x="http://oracle.com/opa/interview/portlet/10.0">x:GoalKnown</qname>
</supported-publishing-event>

 

In the portlet-app element:

<event-definition>
      <qname xmlns:x="http://oracle.com/opa/interview/portlet/10.0">x:GoalKnown</qname>
     <value-type>java.lang.String</value-type>
</event-definition>

 

If you wish to send other events from the plugin, simply declare them portlet.xml for the Oracle Policy Automation Interview Portlet.

Event receiving portlet

We provide a sample portlet that listens to the GoalKnown event; the source code of which can be found in the examples\interview-portlet\event-receiving directory of the Java runtime zip. The event receiving portlet implements the following method to receive the event:

public void processEvent(EventRequest request, EventResponse response) throws PortletException, java.io.IOException {
      String eventName = request.getEvent().getName();
      String eventValue = (String) request.getEvent().getValue();

      response.setRenderParameter("eventName", eventName);
      response.setRenderParameter("eventValue", eventValue);
}

 

Additionally, the receiving portlet is defined as a receiver of the GoalKnown event by way of the following entries in its portlet.xml:

<supported-processing-event>
      <qname xmlns:x="http://oracle.com/opa/interview/portlet/10.0">x:GoalKnown</qname>
</supported-processing-event>

 

<event-definition>
      <qname xmlns:x="http://oracle.com/opa/interview/portlet/10.0">x:GoalKnown</qname>
      <value-type>java.lang.String</value-type>
</event-definition>